//
//  RecommendRootViewController.m
//  CPICMobileServiceApp
//
//  Created by sinosoft on 13-2-28.
//  Copyright (c) 2013年 lizhiwei. All rights reserved.
//

#import "RecommendRootViewController.h"
#import "RCAlertViewUtil.h"
#import "NSString+SBJson.h"
#import "Config.h"
#import "UIImageView+WebCache.h"
#import "ASIFormDataRequest.h"

@interface RecommendRootViewController ()

@end

@implementation RecommendRootViewController
@synthesize TableViewUser,TableRecommendUser;
@synthesize txtUserAccount,txtUserName,txtRecommendName,txtRecommendPhone,txtRecommendCarNum;
@synthesize progress;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.title=@"客户推荐";
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    NSString *bgimage= [accountDefaults objectForKey:@"UserDefaultBgKindKey"];
    
    if ([bgimage isEqualToString:@"蓝色主题风格"]) 
    {
        ADD_BACKGROUND_BUTTONITEM(@"icon640X88@2x.png");
        ADD_LEFT_BUTTONITEM(@"back.png");
        ADD_TITLE_NAMEITEM(@"客户推荐");
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773@2x"]];
    }
    else if([bgimage isEqualToString:@"棕色主题风格"])
    {
        ADD_BACKGROUND_BUTTONITEM(@"icon640X88_01@2x.png");
        ADD_LEFT_BUTTONITEM(@"back_01.png");
        ADD_TITLE_NAMEITEM(@"客户推荐");
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773_01@2x"]];
    }
    else if([bgimage isEqualToString:@"重大节日皮肤"])
    {
        NSData *dataImg_02=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_02];
        NSLog(@"-------找到%@",dataImg_02);
        NSData *dataImg_03=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_03];
        NSData *dataImg_04=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_04];
        
        NSURL *urlSkinImg_02=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_02]];
        NSURL *urlSkinImg_03=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_03]];
        NSURL *urlSkinImg_04=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_04]];
        NSLog(@"-------找到333%@",urlSkinImg_02);
        
        UIImageView * LogoImage = [[UIImageView alloc]init];
        [LogoImage setImageWithURL:urlSkinImg_03 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(LogoImage.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_03];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        LogoImage.image = [UIImage imageWithData:dataImg_03];
        LogoImage.frame = CGRectMake(0, 0, LogoImage.image.size.width/2, LogoImage.image.size.height/2);
        [self.view addSubview:LogoImage];
        
        //--------------------------
        UIButton * CallOutBtn1 = [UIButton buttonWithType:UIButtonTypeCustom];
        CallOutBtn1.frame = CGRectMake(10, 10, 109/2, 57/2);
        UIImageView * Back = [[UIImageView alloc]init];
        [Back setImageWithURL:urlSkinImg_02 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(Back.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_02];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        [Back setImage:[UIImage imageWithData:dataImg_02]];
        [CallOutBtn1 setImage:Back.image forState:UIControlStateNormal];
        [CallOutBtn1 addTarget:self action:@selector(ClickCallOutBtn) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:CallOutBtn1];
        //--------------------------
        
         ADD_TITLE_NAMEITEM(@"客户推荐");
        
        
        UIImageView *bgimage = [[UIImageView alloc]initWithFrame:CGRectMake(0,44, self.view.frame.size.width, self.view.frame.size.height-44)];
        [bgimage setImageWithURL:urlSkinImg_04 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(bgimage.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_04];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        [bgimage setImage:[UIImage imageWithData:dataImg_04]];
        [self.view addSubview:bgimage];
        [bgimage release];
    }


    //添加UITableview
    TableViewUser = [[UITableView alloc]initWithFrame:CGRectMake(5, 60, self.view.frame.size.width, 200) style:UITableViewStyleGrouped];
	TableViewUser.delegate = self;
	TableViewUser.dataSource = self;
    
    TableViewUser.opaque = NO;
    TableViewUser.backgroundView = nil;
    TableViewUser.autoresizingMask = UIViewContentModeTop;
    TableViewUser.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
    TableViewUser.scrollEnabled=NO;
    TableViewUser.backgroundColor=[UIColor clearColor];
    //[TableViewUser reloadData];
	[self.view addSubview:TableViewUser];
    
    
    TableRecommendUser = [[UITableView alloc]initWithFrame:CGRectMake(5, 174, self.view.frame.size.width, 250) style:UITableViewStyleGrouped];
	TableRecommendUser.delegate = self;
	TableRecommendUser.dataSource = self;
    
    TableRecommendUser.opaque = NO;
    TableRecommendUser.backgroundView = nil;
    TableRecommendUser.autoresizingMask = UIViewContentModeTop;
    TableRecommendUser.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
    TableRecommendUser.scrollEnabled=NO;
    TableRecommendUser.backgroundColor=[UIColor clearColor];
    //[TableViewPassword reloadData];
	[self.view addSubview:TableRecommendUser];
    
    UIButton *btnRecommend=[UIButton buttonWithType:UIButtonTypeCustom];
    [btnRecommend setImage:[UIImage imageNamed:@"Submit_suggestion.png"] forState:UIControlStateNormal];
    [btnRecommend setTitle:@"我要推荐" forState:UIControlStateNormal];
    btnRecommend.frame=CGRectMake(86, 370, 310/2, 119/2);
    [btnRecommend addTarget:self action:@selector(doRecommend) forControlEvents:UIControlEventTouchDown];
    [self.view addSubview:btnRecommend];
    
    UILabel * lbSuggestion = [[UILabel alloc]initWithFrame:CGRectMake(86, 358, 310/2, 119/2)];
    lbSuggestion.text = @"我要推荐";
    lbSuggestion.textAlignment = UITextAlignmentCenter;
    lbSuggestion.textColor = [UIColor whiteColor];
    lbSuggestion.backgroundColor = [UIColor clearColor];
    [self.view addSubview:lbSuggestion];
    [lbSuggestion release];

    arrUser=[[NSMutableArray alloc]initWithObjects:@"推荐人账号:",@"推荐人姓名:", nil];
    arrRecommendUser=[[NSMutableArray alloc]initWithObjects:@"被推荐人姓名:",@"被推荐人手机号:",@"被推荐人车牌号:", nil];
}

-(void) ClickCallOutBtn
{
    
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)doRecommend
{
    NSLog(@"================%@",txtUserName.text);
    if (self.txtUserAccount.text == NULL||self.txtUserAccount==nil)
    {
        [self justShowMessage:@"先填写推荐人账号" title:@"提示"];
        return;
    }
    
    if (self.txtUserName.text == NULL||self.txtUserName==nil)
    {
        [self justShowMessage:@"先填写推荐人姓名" title:@"提示"];
        return;
    }
    
    /*if (self.txtRecommendName.text == NULL||self.txtRecommendName==nil)
    {
        [self justShowMessage:@"先填写被推荐人姓名" title:@"提示"];
        return;
    }*/
    
    if (self.txtRecommendPhone.text == NULL||self.txtRecommendPhone==nil)
    {
        [self justShowMessage:@"先填写被推荐人手机号" title:@"提示"];
        return;
    }
    
    if (self.txtRecommendCarNum.text == NULL||self.txtRecommendCarNum==nil)
    {
        [self justShowMessage:@"先填写被推荐人车牌号" title:@"提示"];
        return;
    }
    
    
    NSString * Mobile = txtRecommendPhone.text;
    if (![self isValidateMobile:Mobile])
    {
        [self justShowMessage:@"非法的手机号码,请输入正确的手机号码" title:@""];
        return;
    }
    
    [self setRequest];
}
#pragma UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(tableView==TableViewUser)
    {
        return [arrUser count];
    }
    else
    {
        return [arrRecommendUser count];
    }
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(tableView==TableViewUser)
    {
        static NSString *Identifier=@"Identifier";
        UITableViewCell *cell=(UITableViewCell *)[TableViewUser dequeueReusableCellWithIdentifier:Identifier];
        if (cell==nil)
        {
            cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Identifier]autorelease];
            cell.accessoryType = UITableViewCellAccessoryNone;
            cell.selectionStyle=UITableViewCellSelectionStyleNone;//选中后颜色没变化
            
            if(indexPath.row==0)
            {
                UILabel *lblUserAccount=[[UILabel alloc]initWithFrame:CGRectMake(15, 7, 100, 21)];
                lblUserAccount.backgroundColor=[UIColor clearColor];
                lblUserAccount.text=[arrUser objectAtIndex:indexPath.row];
                lblUserAccount.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:lblUserAccount];
                [lblUserAccount release];
                
                txtUserAccount=[[UITextField alloc]initWithFrame:CGRectMake(117, 4, 183, 31)];
                txtUserAccount.borderStyle=UITextBorderStyleLine;
                txtUserAccount.enabled=NO;
                txtUserAccount.delegate =self;
                txtUserAccount.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:txtUserAccount];
                
                NSLog(@"userinfodefault%@",[[NSUserDefaults standardUserDefaults] objectForKey:DICT_USER_INFO]);
                NSDictionary *dictUserInfo=[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_USER_INFO];
                if (dictUserInfo!=nil)
                {
                    if ([dictUserInfo valueForKey:@"UserAccount"])
                    {
                        txtUserAccount.text = [dictUserInfo valueForKey:@"UserAccount"];
                        NSLog(@"%@",txtUserAccount.text);
                    }
                }
                else
                {
                    [self justShowMessage:@"用户还没登录,请登录系统" title:@"注意"];
                }

            }
            else if(indexPath.row==1)
            {
                UILabel *lblUserName=[[UILabel alloc]initWithFrame:CGRectMake(15, 7, 100, 21)];
                lblUserName.backgroundColor=[UIColor clearColor];
                lblUserName.text=[arrUser objectAtIndex:indexPath.row];
                lblUserName.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:lblUserName];
                [lblUserName release];
                
                txtUserName=[[UITextField alloc]initWithFrame:CGRectMake(117, 4, 183, 31)];
                txtUserName.borderStyle=UITextBorderStyleLine;
                txtUserName.enabled=NO;
                txtUserName.delegate=self;
                txtUserName.returnKeyType = UIReturnKeyDone;
                txtUserName.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:txtUserName];
                
                NSDictionary *dictCustomerInfo=[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_CUSTOMER_INFO];
                if (dictCustomerInfo!=nil)
                {
                    if ([dictCustomerInfo valueForKey:@"userName"])
                    {
                        txtUserName.text = [dictCustomerInfo valueForKey:@"userName"];
                        NSLog(@"%@",txtUserName.text);
                    }
                }
                else
                {
                    //[self justShowMessage:@"用户还没登录,请登录系统" title:@"注意"];
                }

            }
        }
        return cell;
    }
    else
    {
        static NSString *Identifier=@"Identifier";
        UITableViewCell *cell=(UITableViewCell *)[TableViewUser dequeueReusableCellWithIdentifier:Identifier];
        if (cell==nil)
        {
            cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Identifier]autorelease];
            cell.accessoryType = UITableViewCellAccessoryNone;
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            
            if(indexPath.row==0)
            {
                UILabel *lblUserPassword=[[UILabel alloc]initWithFrame:CGRectMake(15, 7, 130, 21)];
                lblUserPassword.backgroundColor=[UIColor clearColor];
                lblUserPassword.text=[arrRecommendUser objectAtIndex:indexPath.row];
                lblUserPassword.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:lblUserPassword];
                [lblUserPassword release];
                
                txtRecommendName=[[UITextField alloc]initWithFrame:CGRectMake(148, 4, 152, 31)];
                txtRecommendName.borderStyle=UITextBorderStyleRoundedRect;
                txtRecommendName.returnKeyType=UIReturnKeyDone;
                txtRecommendName.delegate=self;
                txtRecommendName.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:txtRecommendName];
            }
            else if(indexPath.row==1)
            {
                UILabel *lblUserIdenPassword=[[UILabel alloc]initWithFrame:CGRectMake(15, 7, 130, 21)];
                lblUserIdenPassword.backgroundColor=[UIColor clearColor];
                lblUserIdenPassword.text=[arrRecommendUser objectAtIndex:indexPath.row];
                lblUserIdenPassword.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:lblUserIdenPassword];
                [lblUserIdenPassword release];
                
                txtRecommendPhone=[[UITextField alloc]initWithFrame:CGRectMake(148, 4, 152, 30)];
                txtRecommendPhone.borderStyle=UITextBorderStyleRoundedRect;
                txtRecommendPhone.returnKeyType=UIReturnKeyDone;
                CustomNumbleKeyboardView *customKeyboardView = [[CustomNumbleKeyboardView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 238)];
                customKeyboardView.delegate = self;
                [txtRecommendPhone setInputView:customKeyboardView];
                txtRecommendPhone.delegate=self;
                txtRecommendPhone.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:txtRecommendPhone];
                
                UIButton * Remindbtn = [UIButton buttonWithType:UIButtonTypeInfoDark];
                Remindbtn.frame = CGRectMake(125, 7, 18, 19);
                [Remindbtn addTarget:self action:@selector(remindclick:) forControlEvents:UIControlEventTouchUpInside];
                [cell addSubview:Remindbtn];
            }
            else if(indexPath.row==2)
            {
                UILabel *lblIdenCode=[[UILabel alloc]initWithFrame:CGRectMake(15, 7, 130, 21)];
                lblIdenCode.backgroundColor=[UIColor clearColor];
                lblIdenCode.text=[arrRecommendUser objectAtIndex:indexPath.row];
                lblIdenCode.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:lblIdenCode];
                [lblIdenCode release];
                
                txtRecommendCarNum=[[UITextField alloc]initWithFrame:CGRectMake(148, 4, 152, 31)];
                txtRecommendCarNum.borderStyle=UITextBorderStyleRoundedRect;
                txtRecommendCarNum.returnKeyType=UIReturnKeyDone;
                txtRecommendCarNum.delegate=self;
                txtRecommendCarNum.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:txtRecommendCarNum];
            }
        }
        return cell;
    }
    
    
}

-(void) remindclick:(id)sender
{
    [self justShowMessage:@"需录入正确的手机号码，以便被推荐人能收到正确的推荐验证码，方可完成推荐注册" title:@"系统提示!"];
        return;
}


//数字键盘
- (void)numberKeyBoardInput:(NSInteger) number
{
    NSMutableString *textString = [[[NSMutableString alloc] initWithFormat:@"%@%d",txtRecommendPhone.text,number] autorelease];
    if ([textString length]>11)
    {
        [self justShowMessage:@"手机号码输入不能超过11位!" title:@""];
        return;
    }
    txtRecommendPhone.text = textString;
}

- (void)numberKeyBoardBackspace
{
    NSMutableString* mutableString = [[[NSMutableString alloc] initWithFormat:@"%@", txtRecommendPhone.text] autorelease];
    if ([mutableString length] >=1) {
        NSRange tmpRange;
        tmpRange.location = [mutableString length] - 1;
        tmpRange.length = 1;
        [mutableString deleteCharactersInRange:tmpRange];
    }
    txtRecommendPhone.text = mutableString;
    
}

- (void)numberKeyBoardFinish
{
    [txtRecommendPhone resignFirstResponder];
}

/*手机号码验证*/
-(BOOL) isValidateMobile:(NSString *)mobile
{
    //手机号以13， 15，18开头，八个 \d 数字字符
    NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    return [phoneTest evaluateWithObject:mobile];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    if(textField==txtRecommendName)
    {
        [self SetAnimation:50];
    }
    else if(textField==txtRecommendPhone)
    {
        [self SetAnimation:80];
    }
    else if(textField==txtRecommendCarNum)
    {
        [self SetAnimation:120];
    }
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if(textField==txtRecommendName)
    {
        [self backAnimation:50];
    }
    else if(textField==txtRecommendPhone)
    {
        [self backAnimation:80];
    }
    else if(textField==txtRecommendCarNum)
    {
        [self backAnimation:120];
    }
}
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if (textField==txtUserName) 
    {
        if(range.location>=10)
        {
            return NO;
        }
        else
        {
            return YES;
        }
    }
    
    if(textField==txtRecommendName)
    {
        if(range.location>=10)
        {
            return NO;
        }
        else
        {
            return YES;
        }
    }
    else if(textField==txtRecommendPhone)
    {
        if(range.location>=11)
        {
            return NO;
        }
        else
        {
            return YES;
        }
    }
    else if(textField==txtRecommendCarNum)
    {
        if(range.location>=10)
        {
            return NO;
        }
        else
        {
            return YES;
        }
    }
      return YES;
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

-(void)SetAnimation:(CGFloat)Xorigin
{
    NSTimeInterval animationDuration = 0.30f;
    CGRect frame = self.view.frame;
    //frame.origin.x+=Xorigin;
    frame.origin.y-=Xorigin;
    //frame.size.height +=Xorigin;
    self.view.frame = frame;
    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
    [UIView setAnimationDuration:animationDuration];
    self.view.frame = frame;
    [UIView commitAnimations];
}

-(void)backAnimation:(CGFloat)Xorigin
{
    NSTimeInterval animationDuration = 0.30f;
    CGRect frame = self.view.frame;
    //frame.origin.x -=Xorigin;
    frame.origin.y+=Xorigin;
    //frame.size.height -=Xorigin;
    self.view.frame = frame;
    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
    [UIView setAnimationDuration:animationDuration];
    self.view.frame = frame;
    [UIView commitAnimations];
    // [textField resignFirstResponder];
}

-(void)setRequest//向太保移动平台发送请求报文
{
    if (txtRecommendName.text.length == 0)
    {
        txtRecommendName.text = @"";
    }
    
    //NSString *strRequestCode=@"RequestCode=60701";
    NSString *strRequestData=[NSString stringWithFormat:@"{\"userAccount\":\"%@\",\"userName\":\"%@\",\"recommendByName\":\"%@\",\"recommendByMobilePhone\":\"%@\",\"recommendByCarnum\":\"%@\"}",txtUserAccount.text,txtUserName.text,txtRecommendName.text,txtRecommendPhone.text,txtRecommendCarNum.text];
    NSLog(@"请求报文体:%@",strRequestData);
//    NSString *strUrl=[NSString stringWithFormat:@"%@%@%@",Server_Url,strRequestCode,strRequestData];
//    NSLog(@"++++++++++++++%@",strUrl);
//    strUrl = [strUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];//字符串编码转换
//    
//    NSURL *myurl = [NSURL URLWithString:strUrl];//This method expects URLString to contain any necessary percent escape codes, which are ‘:’, ‘/’, ‘%’, ‘#’, ‘;’, and ‘@’. Note that ‘%’ escapes are translated via UTF-8.
//    NSLog(@"URL:%@",myurl);
    
    ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:Server_Url_Form]];
    
    //设置需要POST的数据，这里提交两个数据，A=a&B=b
    [request setPostValue:@"60701" forKey:@"RequestCode"];
    [request setPostValue:strRequestData forKey:@"RequestData"];
    
    [request setDelegate:self];
    [request setDidFailSelector:@selector(ResponseFail:)];
    [request setDidFinishSelector:@selector(ResonseSuccess:)];
    [request startAsynchronous];
    
    showProgress = YES;
    if (showProgress)
    {
        progress= [[MBProgressHUD alloc]initWithView:self.view];
        [self.view addSubview:progress];
        [self.view bringSubviewToFront:progress];
        progress.labelText = @"加载中...";
        [progress show:YES];
        showProgress = NO;
    }
}

- (void)ResonseSuccess:(ASIHTTPRequest *)request
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    
    NSString *responseString = [request responseString];
    NSLog(@"responseString %@",responseString);
    NSMutableDictionary *dictResponse=[responseString JSONValue];
    NSMutableDictionary *jsonoSubObj = [dictResponse objectForKey:@"head"];
    NSString * ss = [[NSString alloc] initWithFormat:@"%@",[jsonoSubObj objectForKey:@"success"]];
    if ([ss isEqualToString:@"1"])
    {
        //[self justShowMessage:@"提交成功！" title:@"提示"];
        NSString * recommend = [dictResponse valueForKey:@"recommend"];
        NSString * Str = [NSString stringWithFormat:@"推荐成功！推荐码为:%@",recommend];
        UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:Str delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alertView show];
        alertView.delegate = self;
        [alertView release];
    }
    else
    {
        [self justShowMessage:@"提交失败！" title:@"提示"];
    }
}

- (void)ResponseFail:(ASIHTTPRequest *)request
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    
    NSLog(@"服务器连接失败!");
    [self justShowMessage:@"服务器连接失败！" title:@"提示"];
}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(void)dealloc
{
    [txtUserAccount release];
    [txtUserName release];
    [txtRecommendName release];
    [txtRecommendPhone release];
    [txtRecommendCarNum release];
    [arrUser release];
    [arrRecommendUser release];
    [TableViewUser release];
    [TableRecommendUser release];
    [super dealloc];
}

@end
